home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / includes / viewFunctions.php < prev    next >
PHP Script  |  2010-05-19  |  30KB  |  645 lines

  1. <?php
  2. /**
  3.  * File viewer
  4.  *
  5.  * Images : view, slideshow, next, prev, fullSize
  6.  * HTML : view webpage (and not source code)
  7.  * text : inline view
  8.  * other formats : download (Opera) or inline view if possible (IE)
  9.  *
  10.  * parameters : POST data1 (file directory),  data2 (file name),  data3 (="view"),  data4 (action (optional)),  data5 (parameters (optional))
  11.  *
  12.  * PHP version 5
  13.  *
  14.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  15.  * that is available through the world-wide-web at the following URI:
  16.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  17.  * the PHP License and are unable to obtain it through the web, please
  18.  * send a note to license@php.net so we can mail you a copy immediately.
  19.  *
  20.  * @category   NA
  21.  * @package    NA
  22.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  23.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  24.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  25.  * @version    CVS: $Id:$
  26.  * @link       http://www.weezo.net
  27.  * @since      File available since Release 1.0.0
  28.  */
  29.  
  30. /**
  31.  * @desc insert flash mp3 player, and start playing (if autostart is set to true)
  32.  *
  33.  * @param string $completeFilename : complete file name of mp3 file
  34.  * @param string $playerType : 'normal', 'compact', 'minimal'
  35.  * @param string $autoplay : true : start playing when loaded, false don't
  36.  * @param integer $width : player width
  37.  * @param integer $height : player height
  38.  * @param integer $format : if set, use this player (flash,qt,wmp)
  39.  */
  40. function vfInsertAudioPlayer($completeFilename, $playerType='normal', $autoplay=false,$width=false,$height=false,$format=false){
  41.     if($format && ($format=='flash' || $format=='qt' || $format=='wmp')) {}
  42.     // Detect format according to browser support
  43.     elseif    (cfBGetVar('flash'))$format='flash';
  44.     elseif    (cfBGetVar('qt'))    $format='qt';
  45.     elseif    (cfBGetVar('wmp'))    $format='wmp';
  46.     else    return;
  47.  
  48.     if($width===false)    $width=280; if($height===false)    $height=26;
  49.  
  50.      // If file is a playlist, modify it's extension and/or name so /ext/audio.php script can detect flash player is being used and so convert m3u file into an XML format
  51.  
  52.      // If file is not a playlist, convert it into single-file playlist
  53.      if(!$completeFilename) $externalFileName='';
  54.     elseif(cfFileExtension($completeFilename)!='m3u') {
  55.         cfRSetVar('singleMP3', $completeFilename);
  56.         $externalFileName='*singleMP3*.m3u'.(($format=='flash')?'.xml':'');
  57.  
  58.         // Set song label
  59.         if(is_file($completeFilename)){
  60.             require_once(INCLUDE_DIR.'explorerFunctions.php');
  61.             $tags=efGetAudioInfo($completeFilename,false);
  62.             cfRSetVar('singleMP3Label', cfUTF8Encode($tags['label']));
  63.         }
  64.     }
  65.     else $externalFileName=$completeFilename.(($format=='flash')?'.xml':'');
  66.  
  67.     // If file should be reencoded (downgraded bitrate), insert /audio/[bitrate] into external file name
  68.     if($completeFilename) $externalFileName=cfExtAudio($externalFileName, "audio/".cfRGetVar('outputBitRate')."/",'relative');
  69.  
  70.     /**
  71.      * Flash player
  72.      */
  73.     if($format=='flash'){
  74.         if($playerType=='normal') $player='player.swf';
  75.         elseif($playerType=='compact') $player='playerSmall.swf';
  76.         else $player='playerMin.swf';
  77.  
  78.         $args='&bufferSize='.((cfRGetVar('flashPlayerBufferLength'))?cfRGetVar('flashPlayerBufferLength'):'3').'&autoplay='.(($autoplay)?'1':'0').'&volume='.((cfRGetVar('flashPlayerDefaultVolume'))?cfRGetVar('flashPlayerDefaultVolume'):'70').'&browser='.cfGetBrowser().'&rnd='.rand();
  79.  
  80.         // Audio Flash player code
  81.         $playerCode='<object type="application/x-shockwave-flash" data="/js/'.$player.'?file='.$externalFileName.$args.'" width="'.$width.'" height="'.$height.'" id="playerAudio">';
  82.         $playerCode.='<param name="movie" value="/js/'.$player.'?file='.$externalFileName.$args.'">';
  83.         $playerCode.='<param name="wmode" value="transparent">';
  84.         $playerCode.='<embed type="application/x-shockwave-flash" ';
  85.             $playerCode.='name="playerAudio" ';
  86.             $playerCode.='id="playerAudioEmbed" ';
  87.             $playerCode.='src="/js/'.$player.'?file='.$externalFileName.$args.'" ';
  88.             $playerCode.='allowScriptAccess="sameDomain" ';
  89.             $playerCode.='type="application/x-shockwave-flash" ';
  90.             $playerCode.='wmode="transparent" ';
  91.             $playerCode.='pluginspage="http'.((isset($_SERVER['HTTPS']))?'s':'').'://www.macromedia.com/go/getflashplayer"/>';
  92.         $playerCode.='</object>';
  93.     }
  94.     /**
  95.      * Quicktime player
  96.      */
  97.     elseif($format=='qt'){
  98.         $playerCode ='<object id="playerVideo" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
  99.            $playerCode.='width="'.$width.'" height="'.$height.'" codebase="http'.((isset($_SERVER['HTTPS']))?'s':'').'://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0"';
  100.            $playerCode.='align="middle" >';
  101.         $playerCode.='<param name="src" value="'.$externalFileName.'"/>';
  102.         $playerCode.='<param name="autoplay" value="true" /><param name="CONTROLLER" VALUE="true" /><param name="LOOP" VALUE="false" />';
  103.         // Opera & Gecko parameters
  104.         $playerCode.='<embed name="playerVideo" id="playerVideoEmbed" src="'.$externalFileName.'" width="'.$width.'" height="'.$height.'"';
  105.         $playerCode.='pluginspage="http'.((isset($_SERVER['HTTPS']))?'s':'').'://www.apple.com/quicktime/download/" align="middle" autoplay="true"> </embed>';
  106.         $playerCode.='</object>';
  107.         if(!$externalFileName) $playerCode='';
  108.  
  109.     }
  110.     /**
  111.      * Windows Media Player
  112.      */
  113.     elseif($format=='wmp'){
  114.         $playerCode='<object name="NSPlayPlayer " classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="'.$width.'" height="'.$height.'"';
  115.         $playerCode.='codebase="http'.((isset($_SERVER['HTTPS']))?'s':'').'://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,1,5,217"';
  116.         $playerCode.='standby="'.cfUTF8Encode('Microsoft« Windows MediaÖ Player components...').'" type="application/x-oleobject">';
  117.         $playerCode.='<param name="AutoStart" value="1">';
  118.         $playerCode.='<param name="filename" value="'.$externalFileName.'">';
  119.         $playerCode.='<param name="WindowlessVideo" value="1">';
  120.         $playerCode.='<param name="EnableContextMenu" value="1">';
  121.         $playerCode.='<param name="ShowStatusBar" value="1">';
  122.         $playerCode.='<param name="howAudioControls" value="1">';
  123.         $playerCode.='<param name="ShowControls" value="1">';
  124.         $playerCode.='<param name="ShowPositionControls" value="1">';
  125.         $playerCode.='<param name="ShowDisplay" value="0">';
  126.         $playerCode.='<param name="ShowTracker" value="0">';
  127.         $playerCode.='<param name="ShowGotoBar" value="0">';
  128.         $playerCode.='<param name="EnableTracker" value="1">';
  129.         // Opera & Gecko parameters
  130.         $playerCode.='<embed type="application/x-mplayer2" src="'.$externalFileName.'" width="'.$width.'" height="'.$height.'"';
  131.         $playerCode.='ShowAudiocontrols="1" ShowStatusbar="1" ShowControls="1" Showdisplay="0" ShowGotoBar="0" AutoSize="0" ShowCaptioning="0" EnableTracker="0" ShowTracker="0" EnableContextMenu="0" ShowPositionControls="1">';
  132.         $playerCode.='</embed></object>';
  133.     }
  134.     //cfDbg($playerCode,1);
  135.     return $playerCode;
  136. }
  137.  
  138. /**
  139.  * Enter description here...
  140.  *
  141.  * @param string $completeFilename : path and file name of audio file to play
  142.  * @param string $command : passed command :
  143.  *                - firstLoad : display audio file info and player iframe. This command should only be received by main player frame
  144.  *                - playFile : display audio player or send m3u file. This command should only be received by previously created iframe
  145.  *                - change : change parameters (bitrate, player). This command should only be received by main player frame
  146.  * @param string $extraData :
  147.  * @return unknown
  148.  */
  149. function vfViewFileAudio($completeFilename, $command, $extraData=false){
  150.     // set default parameters
  151.     if(!cfRGetVar('audioPlayer')) {
  152.         if(cfBGetVar('flash'))    cfRSetVar('audioPlayer','flash');
  153.         elseif(cfBGetVar('wmp'))cfRSetVar('audioPlayer','wmp');
  154.         elseif(cfBGetVar('qt')) cfRSetVar('audioPlayer','qt');
  155.         else cfRSetVar('audioPlayer','external');
  156.     }
  157.     if(cfRGetVar('audioPlayer')=='embeded') cfRSetVar('audioPlayer','wmp'); // Backward compatibility
  158.     if(!cfRGetVar('outputBitRate')) cfRSetVar('outputBitRate','original');
  159.     if(!cfRGetVar('maxOutputBitRate')) cfRSetVar('maxOutputBitRate','original');
  160.  
  161.  
  162.     /**
  163.      * Quicktime specific playlists (so far iPhone only...), display embed quicktime with qtnext parameters acting as playlist
  164.      */
  165.     if($completeFilename=='*playlist*.m3u' && cfBGetVar('playlistFormat')=='qt'){
  166.         require_once(INCLUDE_DIR.'mobileFunctions.php');
  167.         require_once(INCLUDE_DIR.'mobileExplorerFunctions.php');
  168.  
  169.         // iPhone rotation
  170.         $_ENV['meta']='<meta name="viewport" id="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">';
  171.  
  172.         // Insert header and scripts
  173.         mfInsertHead(array('topControlsExtra'=>mefTopControls()));
  174.         mefInsertScripts();
  175. ?>
  176. <script type="text/javascript">
  177. function updateOrientation(){
  178.     if(window.orientation==undefined) return;
  179.     if(Math.abs(orientation)==90) {
  180.         dgn('viewport').setAttribute("content", "width=480, height=268, user-scalable=yes,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0");
  181.         D.body.style.height='268px';
  182.     }
  183.     else {
  184.         dgn('viewport').setAttribute("content", "width=320, height=416, user-scalable=yes,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0");
  185.         D.body.style.height='416px';
  186.     }
  187. }
  188. </script>
  189. <div id="mainDiv">
  190. <center>
  191. <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="90%" height="50%" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
  192. <?php
  193.         if(cfRGetVar('shufflePlaylist')) $playlist=cfRGetVar('playlistShuffled'); else $playlist=cfRGetVar('playlist');
  194.  
  195.         $nb=0;
  196.         foreach ($playlist as $song){
  197.             // external ref (returned by flash player to browser every time a new song is played)
  198.             if(!isset($song['externalRef'])) $song['externalRef']= base64_encode(cfResourceRelativePath($song['completeFileName']));
  199.             // URL to file - note : no bitrate calculation, as it will be done later by audio.php
  200.             $externalFileName=cfExtAudio(($song['completeFileName']),'','relative');
  201.             // Create XML node
  202.             if(!$nb) echo '<param name="src" value="'.$externalFileName.'">'."\n";
  203.             else echo '<param name="qtnext'.$nb.'" value="<'.$externalFileName.'> T<myself>">'."\n";
  204.             $nb++;
  205.         }
  206.         cfLog('extAccess.php: audio playlist generated from internal playlist. '.$nb.' records generated',LOG_DBG);
  207.  
  208. ?>
  209. <param name="qtnext<?php echo $nb;?>" value="GOTO0">
  210. <param name="autoplay" value="true">
  211. <param name="controller" value="true">
  212. <param name="loop" value="false">
  213. </object></center></div>
  214. <?php
  215.         exit;
  216.     }
  217.  
  218.     /**
  219.      * If player must be opened in a standalone window (so far iPhone only, single tracks)
  220.      */
  221.     if(cfBGetVar('standaloneMediaPlayer')){
  222.         // Byte-range request unsupported by iPhone => no reencoding
  223.         /*
  224.         if(cfRGetVar('maxOutputBitRate')!='original'){
  225.             require_once(INCLUDE_DIR.'outputFunctions.php');
  226.             outDisplayErrorPage('Cannot play reencoded mp3s on iPhone');
  227.         }
  228.         */
  229.         // Update time before client disconnection as no ping will be sent during file play
  230.         cfPingUpdate('force',60*10);
  231.         header('Location: '.cfExtAudio($completeFilename));
  232.         exit;
  233.         cfInsertHEAD(false);
  234. ?>
  235. <form name="zeform" action="<?php echo cfExtAudio($completeFilename)?>" method="POST"></form>
  236. <script type="text/javascript">
  237. D.zeform.submit();
  238. W.history.back();
  239. </script>
  240. <body></body>
  241. <?php
  242.         exit;
  243.     }
  244.  
  245. /*
  246.  ***************************************************************************************************************************
  247.  * Player IFRAME
  248.  ***************************************************************************************************************************
  249.  */
  250.  
  251.     // if display audio player command is received
  252.     if($command=='playFile') {
  253.  
  254.         // Check file's existence, access rights and format
  255.         if(($completeFilename=='*playlist*.m3u' || cfFileRights($completeFilename,'download')) && cfRGetVar('fileViewAllowed') && substr(mimeType(cfFileExtension($completeFilename)),0,5)=='audio'){
  256.             //if(cfRGetVar('audioPlayer')=='flash' && cfFileExtension($completeFilename)!='m3u' && cfFileExtension($completeFilename)!='mp3' && cfFileExtension($completeFilename)!='xml') cfRSetVar('audioPlayer','wmp');
  257.             switch (cfRGetVar('audioPlayer')){
  258.                 case 'wmp':
  259.                 case 'flash':
  260.                 case 'qt':
  261.                     $_ENV['winNoBar']=true;
  262.                     cfInsertHEAD(true);
  263.                     echo '<body class="frame1" style="border:0;margin:0;padding:0;text-align:center;min-width:0px">';
  264.                     echo vfInsertAudioPlayer($completeFilename,'normal',true,false,false,cfRGetVar('audioPlayer'));
  265.                     if(cfRGetVar('audioPlayer')=='flash') echo '<script type="text/javascript">function flashCommand(cmd,args){}</script>';
  266.                     echo '</body></html>';
  267.                     break;
  268.                 case 'external':
  269.                     efSendM3UFile($completeFilename);
  270.                     break;
  271.             }
  272.             exit;
  273.         }
  274.         exit;
  275.     }
  276.  
  277. /*
  278.  ***************************************************************************************************************************
  279.  * Change player / output bit rate command
  280.  ***************************************************************************************************************************
  281.  */
  282.  
  283.     // if a player-parameters update command is passed
  284.     if($command=='change' && $extraData) {
  285.  
  286.         // Change audio player
  287.         $audioPlayer=substr($extraData,0,strpos($extraData,';'));
  288.         if($audioPlayer=='qt' || $audioPlayer=='wmp' || $audioPlayer=='flash' || $audioPlayer=='external') cfRSetVar('audioPlayer',$audioPlayer);
  289.         // Change output bitrate
  290.         $outputBitRate=substr($extraData,strpos($extraData,';')+1);
  291.         if($outputBitRate=='original' || $outputBitRate=='128' || $outputBitRate=='64' || $outputBitRate=='32'){
  292.         if(cfRGetVar('maxOutputBitRate')=='original' || ($outputBitRate!='original' && cfRGetVar('maxOutputBitRate')>=$outputBitRate))
  293.             cfRSetVar('outputBitRate',$outputBitRate);
  294.         }
  295.     }
  296.  
  297. /*
  298.  ***************************************************************************************************************************
  299.  * Display song/playlist information page
  300.  ***************************************************************************************************************************
  301.  */
  302.  
  303.     /*
  304.      * HEAD and JS
  305.       */
  306.     cfInsertHEAD(false);
  307.     ?>
  308.     <script type="text/javascript">
  309. function change(){
  310. var rs,cf=document.comForm;
  311.     if(dgi('wmp').checked==true) rs='wmp;';
  312.     if(dgi('qt').checked==true) rs='qt;';
  313.     if(dgi('flash').checked==true) rs='flash;';
  314.     if(dgi('external').checked==true) rs='external;';
  315.     if(dgi('brOriginal') && dgi('brOriginal').selected==true) rs=rs+'original';
  316.     if(dgi('br128') && dgi('br128').selected==true) rs=rs+'128';
  317.     if(dgi('br64') && dgi('br64').selected==true) rs=rs+'64';
  318.     if(dgi('br32').selected==true) rs=rs+'32';
  319.     cf.data4.value='change';
  320.     cf.data5.value=rs;
  321.     cf.target='_self';
  322.     cf.submit();
  323. }
  324. function init(){
  325.     D.comForm.target="playerIFrame";
  326.     D.comForm.submit();
  327. <?php
  328.     if($command=='firstLoad' && !cfHGetVar('noPopup')) echo "W.resizeTo(dgi('topDiv').offsetWidth+20,85+dgi('topDiv').offsetHeight);\n";// resize and center window
  329.     elseif($command=='firstLoad') echo "winMe.resizeInnerTo(dgi('topDiv').offsetWidth+8,dgi('topDiv').offsetHeight+10);\n";// resize and center window
  330.     elseif($command=='change' && !cfHGetVar('noPopup')) echo "W.resizeTo(dgi('topDiv').offsetWidth+20,50+dgi('topDiv').offsetHeight);";// resize height of window
  331.     elseif($command=='change') echo "alert(dgi('topDiv').offsetWidth);winMe.resizeInnerTo(dgi('topDiv').offsetWidth,dgi('topDiv').offsetHeight);";// resize height of window
  332. ?>
  333. }
  334. </script>
  335. </head>
  336. <?php
  337.     /*
  338.      * BODY
  339.       */
  340.  
  341.     echo '<body class="iframeBody" onload="init()" id="audioFrameBody" style="text-align:center;overflow:hidden">'."\n";
  342.  
  343.     // Standard com form
  344.     outInsertStandardComForm("",cfUTF8Encode(cfDirName(cfResourceRelativePath($completeFilename))),cfUTF8Encode(basename($completeFilename)),'view','playFile');
  345.  
  346.     echo '<div class="frame1" id="topDiv" style="width:300px" width="300">';
  347.     if($completeFilename!='*playlist*.m3u')echo '<div class="frame1Header">'.cfUTF8Encode(cfFileWithoutExtension(basename($completeFilename)))."</div>\n";
  348.     echo '<center>';
  349.     //
  350.     // ID3 TAG display
  351.     //
  352.     if(cfFileExtension($completeFilename)!='m3u' && $id3=efGetAudioInfo($completeFilename)){
  353.         echo '<div class="frame2">'."\n";
  354.         echo "<div class=\"frame2Header\">".cfCaption('explorerAudioFileInfo')."</div>";
  355.  
  356.         echo "<b>".cfCaption('explorerAudioArtist').cfCaption('genSeparator')."</b>".((isset($id3['artist']))?cfUTF8Encode($id3['artist']):'?')."<br>\n";
  357.         echo "<b>".cfCaption('explorerAudioAlbum').cfCaption('genSeparator')."</b>".((isset($id3['album']))?cfUTF8Encode($id3['album']):'?')."<br>\n";
  358.         echo "<b>".cfCaption('explorerAudioTrack').cfCaption('genSeparator')."</b>".((isset($id3['track']))?cfUTF8Encode($id3['track']):'?')."<br>\n";
  359.         echo "<b>".cfCaption('explorerAudioTitle').cfCaption('genSeparator')."</b>".((isset($id3['title']))?cfUTF8Encode($id3['title']):'?')."<br>\n";
  360.         if(isset($id3['genre'])){
  361.             if(is_int($id3['genre']) && $id3['genre']>=0 && $id3['genre']<148) echo "<b>".cfCaption('explorerAudioGenre')."</b>". cfUTF8Encode(id3_get_genre_name($id3['genre']))."<br>\n"; else  echo "<b>".cfCaption('explorerAudioGenre')."</b>".cfUTF8Encode($id3['genre'])."<br>\n";
  362.         }
  363.         else echo "<b>".cfCaption('explorerAudioGenre')."</b> ?<br>\n";
  364.         echo "<b>".cfCaption('explorerAudioYear')."</b>".((isset($id3['year']))?cfUTF8Encode($id3['year']):'?')."<br>\n";
  365.         echo "<b>".cfCaption('genComments')." : </b>".((isset($id3['comment']))?cfUTF8Encode($id3['comment']):'?')."<br>\n";
  366.         echo "</div>";
  367.     }
  368.  
  369.     //
  370.     // PLAYLISTS (m3u files)
  371.     //
  372.     if(cfFileExtension($completeFilename)=='m3u'){
  373.         echo '<div class="frame2">';
  374.         echo '<div class="frame2Header">'.cfCaption('explorerAudioPlaylist')."</div><br/>\n";
  375.         echo '<div style="overflow:scroll;height:15em;">';
  376.         // Internal playlist
  377.         if($completeFilename=='*playlist*.m3u'){
  378.             $i=1;
  379.             // Shuffle playlist if needed
  380.             if(cfRGetVar('shufflePlaylist')){
  381.                 $shuffle=cfRGetVar('playlist');
  382.                 shuffle($shuffle);
  383.                 cfRSetVar('playlistShuffled',$shuffle);
  384.                 unset($shuffle);
  385.                 foreach (cfRGetVar('playlistShuffled') as $value) echo cfUTF8Encode($i++).') '.cfUTF8Encode(cfStrTruncate($value['label'],42))."<br>\n";
  386.             }
  387.             else{
  388.                 foreach (cfRGetVar('playlist') as $value) echo cfUTF8Encode($i++).') '.cfUTF8Encode(cfStrTruncate($value['label'],42))."<br>\n";
  389.             }
  390.         }
  391.         // existing m3u file : open and read playlist content
  392.         elseif(($handle = fopen ($completeFilename, "r"))){
  393.             $nbFilesInM3U=0;
  394.             while (!feof ($handle)) {
  395.                 $m3uFile = trim(fgets($handle, 4096));
  396.                 if(substr($m3uFile,0,1)!="#"){
  397.                     $audioCompleteFileName=cfJoinPathFile(cfDirName($completeFilename),$m3uFile);
  398.                     if(file_exists($audioCompleteFileName) && efFileType($audioCompleteFileName)=='audio' && cfFileRights($audioCompleteFileName,'download')){
  399.                         $nbFilesInM3U++; echo cfUTF8Encode($nbFilesInM3U).') '.cfUTF8Encode(cfStrTruncate($m3uFile,42))."<br>\n";
  400.                     }
  401.                 }
  402.               }
  403.               fclose ($handle);
  404.         }
  405.         echo "</div></div>\n";
  406.     }
  407.  
  408.     //
  409.     // Display player and encoding options
  410.     //
  411.     if(!(cfRGetVar('audioHidePlayerOptions'))){
  412.         echo '<div class="frame2">';
  413.         // Audio player type (wmp or external)
  414.         echo '<div class="frame2Header">'.cfCaption('explorerAudioPlayerOptions')."</div>\n";
  415.         echo "<div style=\"font-weight:bold;\">".cfCaption('explorerAudioPlayer')."</div>";
  416.         echo '<form action="">';
  417.         echo '<input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">';
  418.  
  419.         if(cfBGetVar('flash')) echo '<input type="radio" id="flash" onclick="change()" name="player"'.((cfRGetVar('audioPlayer')=='flash')?(" checked"):("")).">\n". cfCaption('musicCfgFlash')."<br>\n";
  420.         if(cfBGetVar('qt')) echo '<input type="radio" id="qt" onclick="change()" name="player"'.((cfRGetVar('audioPlayer')=='qt')?(" checked"):("")).">\nQuicktime<br>\n";
  421.         if(cfBGetVar('wmp')) echo '<input type="radio" id="wmp" onclick="change()" name="player"'.((cfRGetVar('audioPlayer')=='wmp')?(" checked"):("")).">\n". cfCaption('musicCfgEmbeded')."<br>\n";
  422.         if(cfBGetVar('externalM3U')) echo '<input type="radio" id="external" onclick="change()" name="player"'.((cfRGetVar('audioPlayer')=='external')?(" checked"):("")).">\n". cfCaption('musicCfgExternal')."<br>\n";
  423.         echo '</form>';
  424.         // Output encoding kbps
  425.         echo '<span style="margin-right:1em; font-weight:bold;">'.cfCaption('explorerAudioEncode')."</span>\n";
  426.  
  427.         echo '<select name="encode" size="1" onChange="change()">';
  428.         if(cfRGetVar('maxOutputBitRate')=='original') echo '<option id="brOriginal" value="original"'.((cfRGetVar('outputBitRate')=='original')?' selected':'').'>'.cfCaption('explorerAudioOriginal')."</option>\n";
  429.         if(cfRGetVar('maxOutputBitRate')=='original' || cfRGetVar('maxOutputBitRate')>='128') echo '<option id="br128" value="128"'.((cfRGetVar('outputBitRate')=='128')?' selected':'').'>'.cfCaption('explorerAudio128')."</option>\n";
  430.         if(cfRGetVar('maxOutputBitRate')=='original' || cfRGetVar('maxOutputBitRate')>='64') echo '<option id="br64" value="64"'.((cfRGetVar('outputBitRate')=='64')?' selected':'').'>'.cfCaption('explorerAudio64')."</option>\n";
  431.         echo '<option id="br32" value="32"'.((cfRGetVar('outputBitRate')=='32')?' selected':'').'>'.cfCaption('explorerAudio32')."</option>\n";
  432.         echo '</select>';
  433.         echo "<br><br></div>\n";
  434.     }
  435.     // Player IFRAME
  436.     $ph=array('wmp'=>50,'flash'=>28,'qt'=>28,'external'=>0);
  437.     echo '<iframe name="playerIFrame" width="280px" height="'.$ph[cfRGetVar('audioPlayer')].'px" frameborder=0 scrolling="no"></iframe>';
  438.     echo '</center>';
  439.     outKeysManager();
  440. ?>
  441. </body>
  442. </html>
  443. <?php
  444.     return true;
  445. }
  446.  
  447. /**
  448.  * @desc View images
  449.  *
  450.  * @param string $completeFilename : path and filename
  451.  * @param string $command : action (optional) 'firstLoad', "next", "previous", "fullsize", "normalsize", "slideshow", "stopSlideshow","rotateX" where X is angle
  452.  * @param string $extraData : screen size if "firstLoad", else window size. Format:widthxheight
  453.  */
  454. function vfViewFileImage($completeFilename, $command=false, $extraData=false){
  455.     require(INCLUDE_DIR.'viewImageFunctions.php');
  456.     exit;
  457. }
  458.  
  459. /**
  460.  * @desc view video files
  461.  *
  462.  * @param string $completeFilename : path and filename
  463.  * @param string $command : action (optional) 'firstLoad', 'forceDivxPlugin', 'forceMediaPlayer'
  464.  * @param string $extraData : screen size if "firstLoad", else window size. Format:widthxheight
  465.  */
  466. function vfViewFileVideo($completeFilename, $command=false, $extraData=false){
  467.     require(INCLUDE_DIR.'viewVideoFunctions.php');
  468.     vfvViewVideo($completeFilename,$command,$extraData);
  469.     exit;
  470. }
  471.  
  472. /**
  473.  * @desc view text files
  474.  *
  475.  * @param string $completeFilename
  476.  * @param string $command : "firstLoad" or false
  477.  * @param mixed $extraData : unused
  478.  */
  479. function vfViewFileText($completeFilename, $command=false, $extraData=false){
  480.     // First load of script : resize window and re-call script for displaying file
  481.     if(false && $command=='firstLoad'){
  482.         cfInsertHEAD(false);
  483.         echo '<script language="javascript" type="text/javascript">';
  484.         echo 'function resize(){';
  485.         if(cfHGetVar('noPopup')) echo 'winMe.resizeTo(parent.dd.getWndW()*3/4,parent.dd.getWndH()*3/4); winMe.moveTo(parent.dd.getWndW()/8,parent.dd.getWndH()/8);'."\n";
  486.         else echo 'window.resizeTo(screen.width*3/4,screen.height*3/4); window.moveTo(screen.width/8,screen.height/8);'."\n";
  487.         echo 'document.comForm.submit();}';
  488.         echo '</script>';
  489.         echo '<body onload="javascript:resize()">';
  490.         outInsertStandardComForm($_SERVER['PHP_SELF'],cfUTF8Encode(cfResourceRelativePath($completeFilename)),'','view','reload');
  491.         outKeysManager();
  492.         echo '</body></html>';
  493.         exit;
  494.     }
  495.  
  496.  
  497.  
  498.     // HTML : display page
  499.     if(substr(cfFileExtension($completeFilename),0,3)=='htm' || (cfFileExtension($completeFilename)=='mht' && cfGetBrowser()=='ie')){
  500.         header('Content-Type:'.efFileMimeType($completeFilename));
  501.         header('Content-Disposition:inline; filename="'.cfUTF8Encode(basename($completeFilename))).'"';
  502.         header('Content-Length: '.cfFileSize($completeFilename));        // Close session
  503.         wSession_write_close();
  504.         echo file_get_contents($completeFilename);
  505.         exit;
  506.     }
  507.     // Insert head
  508.     cfInsertHEAD(false);
  509.  
  510.     // Highlighted file types
  511.     global $highlighted;
  512.     if (isset($highlighted[cfFileExtension($completeFilename)])){
  513.         require_once(INCLUDE_DIR.'Text/Highlighter.php');
  514.     }
  515. ?>
  516. <script type="text/javascript" language="javascript">
  517. function keyPressed(e) {
  518.     if (e.keyCode) keycode=e.keyCode; else keycode=e.which;
  519.     if(keycode==27) winMe.closeMe()
  520. }
  521. </script>
  522. </head>
  523. <body onKeyPress="keyPressed(event)" class="viewText">
  524. <div style="width:100%;height:100%;overflow:auto"><div style="padding:0px 5px 5px 5px">
  525. <?php
  526. //echo outDivFrame('frame1',false,'height:100%;overflow:scroll;'.(isset($highlighted[cfFileExtension($completeFilename)])?'background:white':''));
  527.     // Close session
  528.     wSession_write_close();
  529.  
  530.     // Hightlighted language
  531.     if (isset($highlighted[cfFileExtension($completeFilename)])){
  532.         $hl =& Text_Highlighter::factory($highlighted[cfFileExtension($completeFilename)]);
  533.         echo cfUTF8Encode($hl->highlight(file_get_contents($completeFilename)),false,false);
  534.     }
  535.     // Other : display as plain text
  536.     elseif($fp=@fopen($completeFilename,'r')) {
  537.         fclose($fp);
  538.         echo '<pre>'.str_replace('<','<',cfUTF8Encode(file_get_contents($completeFilename))).'</pre>';
  539.     }
  540.     echo '</div></div></body></html>';
  541.     exit;
  542. }
  543.  
  544. /**
  545.  * @desc VIEW FILE IN A DEDICATED WINDOW
  546.  *         specific file types :
  547.  *         - audio (vfViewFileAudio)
  548.  *         - video (vfViewFileVideo)
  549.  *         - image (vfViewFileImage)
  550.  *         - text (vfViewFileText)
  551.  * Note : parameters have previously been utf-8 decoded
  552.  *
  553.  * @param string $completeFilename : path and filename of file to view
  554.  * @param string $data3
  555.  * @param string $data4
  556.  * @param string $data5
  557.  */
  558. function vfViewFile($completeFilename, $data3=false, $data4=false, $data5=false){
  559.     $cfFileRightsOK=false;
  560.  
  561.     if(substr($completeFilename,0,14)=='*resSpecific*/' && cfRGetVar('extAccessFunction')) {
  562.         $extAccessFunction = create_function('$completeFilename', cfRGetVar('extAccessFunction'));
  563.         $externalFilename=$completeFilename;
  564.         $completeFilename=$extAccessFunction($completeFilename);
  565.         if($completeFilename) $cfFileRightsOK=true;
  566.     }
  567.  
  568.     // Set close URL back to resource for frameless display
  569.     $_ENV['winCloseURL']='/res/'.cfRGetVar('type').'/'.cfRGetVar('subType').'/'.cfRGetVar('baseFile');
  570.  
  571.     // if download/view not authorized
  572.     if($data3!='view' || !cfRGetVar('fileViewAllowed') || ($completeFilename!='*playlist*.m3u' && (!$cfFileRightsOK && !cfFileRights($completeFilename,'download')))) {
  573.         // Hide actual filepath
  574.         if(isset($externalFilename)) $completeFilename=$externalFilename;
  575.         else $completeFilename=str_replace('*resourceBasePath*','',cfResourceRelativePath($completeFilename));
  576.         // Error page
  577.         outDisplayErrorPage(cfCaption('explorerErrorView').'<br/>'.cfUTF8Encode($completeFilename),false,false);
  578.         return false;
  579.     }
  580.     // Get file mime type
  581.     $fileType=efFileType($completeFilename);
  582.  
  583.     // Correct mime type for text_highlighted files
  584.     global $highlighted;
  585.     $highlighted=array("c"=>"CPP","cpp"=>"CPP","css"=>"CSS","dtd"=>"DTD","java"=>"JAVA","js"=>"JAVASCRIPT","sql"=>"SQL","mysql"=>"MYSQL","perl"=>"PERL","php"=>"PHP","py"=>"PYTHON","ruby"=>"RUBY","xml"=>"XML","vbs"=>"VBSCRIPT","bas"=>"VBSCRIPT","ctl"=>"VBSCRIPT","cls"=>"VBSCRIPT","frm"=>"VBSCRIPT");
  586.     if(isset($highlighted[cfFileExtension($completeFilename)])) $fileType='text';
  587.  
  588.     // Log
  589.     if($data4=='firstLoad') cfLog(cfUTF8Decode(cfCaption('logFileView',cfUTF8Encode($completeFilename),false,false,true)),LOG_DET);
  590.  
  591.     // Reset original name of *resSpecific* filenames
  592.     if(isset($externalFilename)) $completeFilename=$externalFilename;
  593.  
  594.     /**
  595.      * Mobile devices: use specific scripts
  596.      */
  597.     if(cfIsMobile()) require(INCLUDE_DIR.'mobileViewFunctions.php');
  598.     if(cfIsMobile('iPhone','wii')){
  599.         return mvfViewFile($completeFilename, $data4, $data5, $fileType);
  600.     }
  601.  
  602.     // Display file according to format
  603.     switch($fileType){
  604.         case 'audio':
  605.             return vfViewFileAudio($completeFilename, $data4, $data5);
  606.         break;
  607.         case 'image':
  608.             return vfViewFileImage($completeFilename, $data4, $data5);
  609.         break;
  610.         case 'video':
  611.             if(cfIsMobile('wii')) return mvfViewFile($completeFilename, $data4, $data5, $fileType); // iPhone: go to mobile view
  612.             return vfViewFileVideo($completeFilename, $data4, $data5);
  613.         break;
  614.         case 'text':
  615.             cfLogContentAccess($completeFilename);
  616.             return vfViewFileText($completeFilename, $data4, $data5);
  617.         break;
  618.         // Other files formats
  619.         default:
  620.             cfLogContentAccess($completeFilename);
  621.             // JS file : treat as text file
  622.             if(efFileMimeType($completeFilename)=='application/x-javascript') return vfViewFileText($completeFilename, $data4, $data5);
  623.             if(cfFileExtension($completeFilename)=='url'){
  624.                 $c=file_get_contents($completeFilename);
  625.                 if(stripos($c,'url=')) {
  626.                     $c=substr($c,stripos($c,'url=')+4);
  627.                     if(strpos($c,"\n")) $c=trim(substr($c,0,strpos($c,"\n")));
  628.                     header('Location: '.$c);
  629.                     exit;
  630.                 }
  631.             }
  632.  
  633.             header('Content-Type:'.efFileMimeType($completeFilename));
  634.             header('Content-Disposition:inline; filename="'.cfUTF8Encode(basename($completeFilename))).'"';
  635.             header('Content-Length: '.cfFileSize($completeFilename));
  636.             header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
  637.             header("Expires: 0");
  638.             wSession_write_close();
  639.             cfStreamFile($completeFilename,false,cfUGetVar('downloadSpeedLimit'));
  640.             if(cfIsWII()) outKeysManager();
  641.             exit;
  642.         }
  643.     return false;
  644. }
  645. ?>